package cn.appsys.controller.developer;

import cn.appsys.pojo.AppInfo;
import cn.appsys.pojo.BackendUser;
import cn.appsys.pojo.DevUser;
import cn.appsys.service.backend.UserLoginService;
import cn.appsys.service.developer.DevUserLoginService;
import cn.appsys.tools.Constants;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/devuser")
public class DevUserLoginController {
    @Resource
    private DevUserLoginService devUserLoginService;
    /**
     * 跳转到登录页面
     * @return
     */
    @RequestMapping("/login")
    public  String login(){
        return "devlogin";
    }

    /**
     * 登录
     * @param devCode
     * @param devPassword
     * @param request
     * @param session
     * @return
     */
    @RequestMapping(value="/dologin",method=RequestMethod.POST)
    public String doLogin(@RequestParam String devCode, @RequestParam String devPassword, HttpServletRequest request, HttpSession session){

        DevUser devUser=devUserLoginService.checkLoginBiz(devCode,devPassword);
        if (devUser!=null){
            session.setAttribute(Constants.DEV_USER_SESSION,devUser);
            return "developer/main";
        }else {
            //页面跳转（login.jsp）带出提示信息--转发
            request.setAttribute("error", "用户名或密码不正确");
            return "devlogin";
        }

    }

    @RequestMapping("/adddev")
    public String adddev(){

        return "developer/appversionadd";
    }
}
